<?php

namespace App\Trip\Wechat\MiniApp;

use EasyWeChat\Kernel\Exceptions\InvalidArgumentException;

class WechatMiniApp
{
    private array       $config;
    private Application $application;

    public function __construct(array|MiniAppConfig $config = null)
    {
        $this->setConfig($config);
    }

    /**
     * @throws InvalidArgumentException
     */
    public function setConfig($config = null)
    {
        if ($config instanceof MiniAppConfig) {
            $this->config = $config->getConfig();
        } else {
            $this->config = (new MiniAppConfig($config))->getConfig();
        }
        $this->application = new Application($this->config);
    }

    public function getApplication(): Application
    {
        return $this->application;
    }
}